<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- Copyright © 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<title>Output Template (GNU Compiler Collection (GCC) Internals)</title>

<meta name="description" content="Output Template (GNU Compiler Collection (GCC) Internals)">
<meta name="keywords" content="Output Template (GNU Compiler Collection (GCC) Internals)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Option-Index.html" rel="index" title="Option Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Machine-Desc.html" rel="up" title="Machine Desc">
<link href="Output-Statement.html" rel="next" title="Output Statement">
<link href="RTL-Template.html" rel="prev" title="RTL Template">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
span:hover a.copiable-link {visibility: visible}
-->
</style>


</head>

<body lang="en">
<div class="section-level-extent" id="Output-Template">
<div class="nav-panel">
<p>
Next: <a href="Output-Statement.html" accesskey="n" rel="next">C Statements for Assembler Output</a>, Previous: <a href="RTL-Template.html" accesskey="p" rel="prev">RTL Template</a>, Up: <a href="Machine-Desc.html" accesskey="u" rel="up">Machine Descriptions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h3 class="section" id="Output-Templates-and-Operand-Substitution"><span>17.5 Output Templates and Operand Substitution<a class="copiable-link" href="#Output-Templates-and-Operand-Substitution"> &para;</a></span></h3>
<a class="index-entry-id" id="index-output-templates"></a>
<a class="index-entry-id" id="index-operand-substitution"></a>

<a class="index-entry-id" id="index-_0025-in-template"></a>
<a class="index-entry-id" id="index-percent-sign"></a>
<p>The <em class="dfn">output template</em> is a string which specifies how to output the
assembler code for an instruction pattern.  Most of the template is a
fixed string which is output literally.  The character &lsquo;<samp class="samp">%</samp>&rsquo; is used
to specify where to substitute an operand; it can also be used to
identify places where different variants of the assembler require
different syntax.
</p>
<p>In the simplest case, a &lsquo;<samp class="samp">%</samp>&rsquo; followed by a digit <var class="var">n</var> says to output
operand <var class="var">n</var> at that point in the string.
</p>
<p>&lsquo;<samp class="samp">%</samp>&rsquo; followed by a letter and a digit says to output an operand in an
alternate fashion.  Four letters have standard, built-in meanings described
below.  The machine description macro <code class="code">PRINT_OPERAND</code> can define
additional letters with nonstandard meanings.
</p>
<p>&lsquo;<samp class="samp">%c<var class="var">digit</var></samp>&rsquo; can be used to substitute an operand that is a
constant value without the syntax that normally indicates an immediate
operand.
</p>
<p>&lsquo;<samp class="samp">%n<var class="var">digit</var></samp>&rsquo; is like &lsquo;<samp class="samp">%c<var class="var">digit</var></samp>&rsquo; except that the value of
the constant is negated before printing.
</p>
<p>&lsquo;<samp class="samp">%a<var class="var">digit</var></samp>&rsquo; can be used to substitute an operand as if it were a
memory reference, with the actual operand treated as the address.  This may
be useful when outputting a &ldquo;load address&rdquo; instruction, because often the
assembler syntax for such an instruction requires you to write the operand
as if it were a memory reference.
</p>
<p>&lsquo;<samp class="samp">%l<var class="var">digit</var></samp>&rsquo; is used to substitute a <code class="code">label_ref</code> into a jump
instruction.
</p>
<p>&lsquo;<samp class="samp">%=</samp>&rsquo; outputs a number which is unique to each instruction in the
entire compilation.  This is useful for making local labels to be
referred to more than once in a single template that generates multiple
assembler instructions.
</p>
<p>&lsquo;<samp class="samp">%</samp>&rsquo; followed by a punctuation character specifies a substitution that
does not use an operand.  Only one case is standard: &lsquo;<samp class="samp">%%</samp>&rsquo; outputs a
&lsquo;<samp class="samp">%</samp>&rsquo; into the assembler code.  Other nonstandard cases can be
defined in the <code class="code">PRINT_OPERAND</code> macro.  You must also define
which punctuation characters are valid with the
<code class="code">PRINT_OPERAND_PUNCT_VALID_P</code> macro.
</p>
<a class="index-entry-id" id="index-_005c"></a>
<a class="index-entry-id" id="index-backslash"></a>
<p>The template may generate multiple assembler instructions.  Write the text
for the instructions, with &lsquo;<samp class="samp">\;</samp>&rsquo; between them.
</p>
<a class="index-entry-id" id="index-matching-operands"></a>
<p>When the RTL contains two operands which are required by constraint to match
each other, the output template must refer only to the lower-numbered operand.
Matching operands are not always identical, and the rest of the compiler
arranges to put the proper RTL expression for printing into the lower-numbered
operand.
</p>
<p>One use of nonstandard letters or punctuation following &lsquo;<samp class="samp">%</samp>&rsquo; is to
distinguish between different assembler languages for the same machine; for
example, Motorola syntax versus MIT syntax for the 68000.  Motorola syntax
requires periods in most opcode names, while MIT syntax does not.  For
example, the opcode &lsquo;<samp class="samp">movel</samp>&rsquo; in MIT syntax is &lsquo;<samp class="samp">move.l</samp>&rsquo; in Motorola
syntax.  The same file of patterns is used for both kinds of output syntax,
but the character sequence &lsquo;<samp class="samp">%.</samp>&rsquo; is used in each place where Motorola
syntax wants a period.  The <code class="code">PRINT_OPERAND</code> macro for Motorola syntax
defines the sequence to output a period; the macro for MIT syntax defines
it to do nothing.
</p>
<a class="index-entry-id" id="index-_0023-in-template"></a>
<p>As a special case, a template consisting of the single character <code class="code">#</code>
instructs the compiler to first split the insn, and then output the
resulting instructions separately.  This helps eliminate redundancy in the
output templates.   If you have a <code class="code">define_insn</code> that needs to emit
multiple assembler instructions, and there is a matching <code class="code">define_split</code>
already defined, then you can simply use <code class="code">#</code> as the output template
instead of writing an output template that emits the multiple assembler
instructions.
</p>
<p>Note that <code class="code">#</code> only has an effect while generating assembly code;
it does not affect whether a split occurs earlier.  An associated
<code class="code">define_split</code> must exist and it must be suitable for use after
register allocation.
</p>
<p>If the macro <code class="code">ASSEMBLER_DIALECT</code> is defined, you can use construct
of the form &lsquo;<samp class="samp">{option0|option1|option2}</samp>&rsquo; in the templates.  These
describe multiple variants of assembler language syntax.
See <a class="xref" href="Instruction-Output.html">Output of Assembler Instructions</a>.
</p>
</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Output-Statement.html">C Statements for Assembler Output</a>, Previous: <a href="RTL-Template.html">RTL Template</a>, Up: <a href="Machine-Desc.html">Machine Descriptions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
